//
//  ClassTopTableViewCell.m
//  FaceRecognition
//
//  Created by syun on 17/2/9.
//  Copyright © 2017年 Sylar. All rights reserved.
//

#import "ClassTopTableViewCell.h"

@implementation ClassTopTableViewCell

{
    NSArray * imagesArr;
    NSMutableArray * headImageArr;
    NSMutableArray * nameArr;
 
}
@synthesize markLabel,nameLabel,headImage;
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self) {
        self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
        
        headImageArr = [NSMutableArray array];
        nameArr = [NSMutableArray array];
        
        markLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 12, 200, 14)];
        markLabel.textAlignment = NSTextAlignmentLeft;
        markLabel.text = @"2月勤奋榜";
        markLabel.textColor = DEFAULTCOLOR;
        markLabel.font = [UIFont systemFontOfSize:14];
        [self addSubview:markLabel];
        
    
        UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(SCREENWIDTH-200, 12, 200-15-4-7, 14)];
        lab.textColor = [UIColor colorWithHexString:@"979797"];
        lab.text = @"查看排名";
        lab.textAlignment = NSTextAlignmentRight;
        lab.font = [UIFont systemFontOfSize:14];
        lab.userInteractionEnabled = YES;
        [self addSubview:lab];
        
        UIImageView * rightArrow = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(lab.frame)+4, 13, 7, 13)];
        rightArrow.image = [UIImage imageNamed:@"arrow_right_"];
        rightArrow.userInteractionEnabled = YES;
        [self addSubview:rightArrow];
        
        
        _rankButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _rankButton.frame = CGRectMake(0, 0, 200, 14);
        _rankButton.contentHorizontalAlignment = NSTextAlignmentRight;
        [lab addSubview:_rankButton];
        
        float w = 53;
        float s = (SCREENWIDTH - 53*3)/6;
        
        imagesArr = @[@"statistics_ranking1_",@"statistics_ranking2_",@"statistics_ranking3_"];
        
        for (int i = 0; i<3; i++) {
            
            headImage = [[UIImageView alloc]initWithFrame:CGRectMake(s+ SCREENWIDTH/3 * i,CGRectGetMaxY(markLabel.frame)+16, w, w)];
            headImage.tag = 100+i;
            headImage.layer.cornerRadius = 53/2;
            [self addSubview:headImage];
            
            UIImageView * rankImage = [[UIImageView alloc]initWithFrame:CGRectMake((53-59)/2, 53/2+5, 59, 31)];
            rankImage.image = [UIImage imageNamed:[imagesArr objectAtIndex:i]];
            [headImage addSubview:rankImage];
            
            nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREENWIDTH/3*i, CGRectGetMaxY(headImage.frame)+13, SCREENWIDTH/3, 13)];
            nameLabel.textAlignment = NSTextAlignmentCenter;
            nameLabel.font = [UIFont systemFontOfSize:13];
            nameLabel.textColor = [UIColor colorWithHexString:@"3b3b3b"];
            [self addSubview:nameLabel];
            
            [headImageArr addObject:headImage];
            [nameArr addObject:nameLabel];
            
        }
    }
    
    return self;
}

- (void)setDataForCell:(NSMutableArray *)modelArr
{
    for (int i = 0 ; i<headImageArr.count; i++) {
        
        RankModel * model =[modelArr objectAtIndex:i];
        
        UIImageView * ima = [headImageArr objectAtIndex:i];
        [ima sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",REQUESTIMAGEURL, model.logo]] placeholderImage:[UIImage imageNamed:@"personalsettings_switchloading_pic_"]];
        UILabel * nameLable = [nameArr objectAtIndex:i];
        
        if (model.username) {
            
            nameLable.text = [NSString stringWithFormat:@"%@",model.username];
        }else
        {
            nameLable.text = @"虚席以待";
        }
        
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
